package cate.game.pvp.guildwar.data;

import cate.game.framework.ModuleMan;
import cate.game.pvp.guildwar.data.msg.*;
import cate.game.role.Role;
import cate.game.role.res.guild.po.GuildPO;
import easy.java.dev.note.NoteClass;

import java.util.List;

@NoteClass("公会战-Game发送消息模块")
public class GWGameMessagingModule extends ModuleMan {

    @Override
    public void initDependent() throws Exception {
        serverConnect();
    }

    /**
     * 服务器连接
     */
    public void serverConnect() {
        game.rpcSend().fireAndForgetCross(GWInnerMsg.GAME_CONNECT, game.config.srvId);
    }

    /**
     * 报名
     * @param list
     */
    public boolean sign(List<GWGuildProfile> list) {
        try {
            return game.rpcSend().requestResponseCross(GWInnerMsg.SIGN, GWSignInnerReq.of(game.config.srvId, list), Boolean.class);
        } catch (Exception e) {
            log.error("", e);
            return false;
        }
    }

    /**
     * 申请一方数据
     * @param data
     */
    public void applySide(GWSideApplyInnerReq data) {
        game.rpcSend().fireAndForgetGame(GWInnerMsg.G2G_APPLY_SIDE, data.tarSrvId, data);
    }

    /**
     * 同步一方数据
     * @param data
     */
    public void sendSideUpdate(GWSideInnerUpdate data) {
        game.rpcSend().fireAndForgetGame(GWInnerMsg.G2G_SIDE_UPDATE, data.tarSrvId, data);
    }

    /**
     * 更新功勋榜
     * @param role
     */
    public void recordRoleRank(Role role){
        game.rpcSend().fireAndForgetCross(GWInnerMsg.RECORD_ROLE_RANK, GWRoleRankRecordInnerReq.of(role));
    }

    /**
     * 更新公会榜
     * @param guild
     * @return
     */
    public boolean recordGuildRank(GuildPO guild) {
        GWGuildProfile profile = GWGuildProfile.of(game.config.srvId, guild);
        try {
            return game.rpcSend().requestResponseCross(GWInnerMsg.RECORD_GUILD_RANK, GWGuildRankRecordInnerReq.of(profile, guild.war.point), Boolean.class);
        } catch (Exception e) {
            return false;
        }
    }



    /**
     * 查看公会榜
     * @param guildUid
     * @return
     */
    public GWGuildRankInnerResp getGuildRank(String guildUid) {
        return game.rpcSend().requestResponseCross(GWInnerMsg.GET_GUILD_RANK, guildUid, GWGuildRankInnerResp.class);
    }

    /**
     * 查看玩家榜
     * @param roleUid
     * @return
     */
    public GWRoleRankInnerResp getRoleRank(String roleUid) {
        return game.rpcSend().requestResponseCross(GWInnerMsg.GET_ROLE_RANK, roleUid, GWRoleRankInnerResp.class);
    }

    /**
     * 查看冠军榜
     * @return
     */
    public GWChampionInnerResp getChampion(){
        return game.rpcSend().requestResponseCross(GWInnerMsg.GET_CHAMPION, null, GWChampionInnerResp.class);
    }

    /**
     * 冠军点赞
     * @param season
     */
    public void admireChampion(int season){
        game.rpcSend().fireAndForgetCross(GWInnerMsg.ADMIRE_CHAMPION, season);
    }







}
